/**
 * 
 */
package com.rio.dandan.dao.impl;

import java.util.List;

import com.rio.dandan.bean.PageBean;
import com.rio.dandan.dao.DaoSupport;
import com.rio.dandan.dao.UserAccountDao;
import com.rio.dandan.pojo.UserAccount;

/**
 * 
 * UserAccountDaoImpl.java
 * 
 * @author 宋陆
 * @version 1.0 2014年5月18日
 */
public class UserAccountDaoImpl extends DaoSupport implements UserAccountDao {

    /**
     * @see com.rio.dandan.dao.UserAccountDao#findUserAccount(com.rio.dandan.bean.PageBean)
     */
    @SuppressWarnings("unchecked")
    @Override
    public PageBean<UserAccount> findUserAccount(PageBean<UserAccount> pageBean) {
        String listHql = "from UserAccount as u where u.status<>-1 order by u.regTime desc";
        String countHql = "select count(*) from UserAccount as u where u.status<>-1";
        Object[] params = new Object[] {};
        List<UserAccount> rows = super.find(listHql, params, pageBean.getStart(), pageBean.getLimit(), true);
        pageBean.setRows(rows);
        int total = super.count(countHql, params);
        pageBean.setTotal(total);
        return pageBean;
    }

    /**
     * @see com.rio.dandan.dao.UserAccountDao#getUserAccount(java.lang.String)
     */
    @Override
    public UserAccount getUserAccount(String uid) {
        return get(UserAccount.class, uid);
    }

    /**
     * @see com.rio.dandan.dao.UserAccountDao#getUserAccountByAccount(java.lang.String)
     */
    @SuppressWarnings("unchecked")
    @Override
    public UserAccount getUserAccountByAccount(String account) {
        String hql = "from UserAccount where Status<>-1 and Username=?";
        Object[] params = new Object[] { account };
        List<UserAccount> list = find(hql, params, true);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    /**
     * @see com.rio.dandan.dao.UserAccountDao#saveUserAccount(com.rio.dandan.pojo.UserAccount)
     */
    @Override
    public UserAccount saveUserAccount(UserAccount userAccount) {
        save(userAccount);
        return userAccount;
    }

    /**
     * @see com.rio.dandan.dao.UserAccountDao#updateUserAccount(com.rio.dandan.pojo.UserAccount)
     */
    @Override
    public UserAccount updateUserAccount(UserAccount userAccount) {
        update(userAccount);
        return userAccount;
    }

}
